using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IWS.Lib.Utilities.Web
{
	[DefaultProperty("Text")]
	[ToolboxData("<{0}:MessageBox runat=server></{0}:MessageBox>")]
	public class MessageBox : WebControl
	{
		public enum Type
		{
			Normal = 0,
			Error = 1
		}
		private Type _MessageType;
		private string _ErrorCssClass;
		private string _NormalCssClass;
		private string _Text = "[MessageBox]";

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public string Text
		{
			get
			{
				String s = this._Text;
				return ((s == null) ? String.Empty : s);
			}

			set
			{
				_Text = value;
			}
		}

		[Bindable(true)]
		[Category("Behavior")]
		[DefaultValue("Normal")]
		[Localizable(true)]
		public Type MessageType
		{
			get
			{
				return this._MessageType;
			}

			set
			{
				this._MessageType = value;
			}
		}

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("ErrorMessageBox")]
		[Localizable(true)]
		public string ErrorCssClass
		{
			get
			{
				String s = this._ErrorCssClass;
				return ((s == null) ? String.Empty : s);
			}

			set
			{
				this._ErrorCssClass = value;
			}
		}

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("NormalMessageBox")]
		[Localizable(true)]
		public string NormalCssClass
		{
			get
			{
				String s = this._NormalCssClass;
				return ((s == null) ? String.Empty : s);
			}

			set
			{
				this._NormalCssClass = value;
			}
		}

		protected override void RenderContents(HtmlTextWriter output)
		{
			string css = "";
			if (this.MessageType == MessageBox.Type.Normal)
			{
				if (this.NormalCssClass.Length > 0)
					css = " class=" + this.NormalCssClass;
				else if (this.CssClass.Length > 0)
					css = " class=" + this.CssClass;
			}
			else if (this.MessageType == MessageBox.Type.Error)
			{
				if (this.ErrorCssClass.Length > 0)
					css = " class=" + this.ErrorCssClass;
				else if (this.CssClass.Length > 0)
					css = " class=" + this.CssClass;
			}
			else if (this.CssClass.Length > 0)
			{
				css = this.CssClass;
			}

			output.Write("<div" + css + ">" + this.Text + "</div>");
		}
		public void ShowMessage(string message)
		{
			this.Text = message;
			this.Visible = true;
		}
		public void ShowMessage(string message, IWS.Lib.Utilities.Web.MessageBox.Type type)
		{
			this.MessageType = type;
			this.Visible = true;
			this.Text = message;
		}
		public void HideMessage()
		{
			this.Visible = false;
		}
	}
}
